﻿using Sidvall.Serialization;

namespace Sidvall.Net
{
    public class NameValueHeaderValue
    {
        #region Public Members

        public string Name { get; set; }
        public string Value { get; set; }

        #region Copy

        public NameValueHeaderValue Copy()
        {
            var item = new NameValueHeaderValue()
            {
                Name = this.Name,
                Value = this.Value,
            };
            return item;
        }

        #endregion
        #region IsEqual

        public bool IsEqual(NameValueHeaderValue obj)
        {
            return IsEqual(this, obj);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            if (string.IsNullOrWhiteSpace(this.Name))
                return string.Empty;
            if (string.IsNullOrWhiteSpace(this.Value))
                return string.Empty;
            return this.Name + ": " + this.Value;
        }

        #endregion

        #region IsEqual - Static

        public static bool IsEqual(NameValueHeaderValue item1, NameValueHeaderValue item2)
        {
            if (item1 == null)
            {
                if (item2 == null)
                    return true;
                else
                    return false;
            }
            else if (item2 == null)
                return false;
            if (!item1.Name.Equals(item2.Name, true, System.StringComparison.OrdinalIgnoreCase))
                return false;
            if (!item1.Value.Equals(item2.Value, true, System.StringComparison.OrdinalIgnoreCase))
                return false;
            return true;
        }

        #endregion

        #endregion
    }
}
